﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Reflection;
using System.Diagnostics;

namespace FontTool
{
    public partial class Editor : Form
    {
        public delegate void sendRefreshRequest();
        public sendRefreshRequest refreshRequest;

        #region Draw Attributes
        //drawing objects
        Pen nPen = new Pen(Color.Black, 1);
        Font ffont = new Font("Arial", 7);
        Brush nBrush = new SolidBrush(Color.Black);

        Graphics gfx;
        Bitmap offscreenbmp;
        #endregion

        #region objects
        //creating references of used object in here since they are used more than just one place
        nFont _Font { get; set; }
        nCharacter nchar;
        nCharacter _Char
        {
            get
            {
                return nchar;
            }
            set
            {
                nchar = value;
                img = Image.FromFile(nchar._ImageUri);
            }
        }
        #endregion

        #region lines
        //lines representing each parameter of font;
        public nLine _baseX;
        public nLine _baseY;
        public nLine _Leading;
        public nLine _xHeight;
        public nLine _capHeight;
        public nLine _ascenderHeight;
        public nLine _descenderHeight;
        public nLine _Width;
        #endregion

        #region mixed attributes
        PointF imageLocation;
        Image img;

        float imageScale = 1f;
        float imageScaleIncrFactor = 1.2f;
        float imageScaleDescrFactor = 0.8f;

        bool previewDefault = true;
        bool drawLines = true;

        PointF originAnchor;
        float moveAnchorFactor = 0.1f;

        RectangleF boundingBox = new RectangleF();
        int imgWidth = 20;

        string[] _zoomMenu = { "default", "25%", "50%", "75%", "100%", "125%", "150%", "175%", "200%" };

        private bool moveWidthLine = false;
        private bool moveAnchorLine = false;
        private bool runStandAlone = false;
        #endregion

        #region Constructor: Editor
        /*
         * Original constructor took two variables as a parameters to initialize
         * font and character objects;
         * For testing purposes and to prevent keep opening FontTool.Window constructor
         * was changed and now its uses dummy objects;
         */
        public Editor(nFont font, nCharacter ch)
        {
            _Font = font;
            _Char = ch;
            //}

            //public Editor()
            //{
            InitializeComponent();
            initToolTips();

            if (runStandAlone)
            {
                _Font = testFont();
                _Char = testCharacter();
            }

            zoomContextMenu.Items.Clear();
            for (int i = 0; i < _zoomMenu.Length; i++)
                zoomContextMenu.Items.Add(_zoomMenu[i]);
            zoomContextMenu.ItemClicked += new ToolStripItemClickedEventHandler(zoomContextMenu_ItemClicked);

            originAnchor = _Char.AnchorPoint;
            propertyGrid1.SelectedObject = _Char;
            timerUpdatePreview.Tick += new EventHandler((o, so) =>
            {
                updatePreview();
                timerUpdatePreview.Stop();
                timerUpdatePreview.Enabled = false;
            });

            offscreenbmp = new Bitmap(panelpreview.Width, panelpreview.Height);
            gfx = Graphics.FromImage(offscreenbmp);
            img = Image.FromFile(_Char._ImageUri);

            initDefaultLines();

            if (_Font != null)
                reInitLinesAndImgLocation();
            updatePreviewTick();
            initBoundingBox();

            this.MouseWheel += new MouseEventHandler(Editor_MouseWheel);

            if (!runStandAlone)
            {
                dataGridViewInit();
                dataGridViewLoad();

                foreach (DataGridViewRow row in dataGridViewGlyphs.Rows)
                    foreach (DataGridViewCell cell in row.Cells)
                        if (cell.ToolTipText == _Char.Name)
                        {
                            dataGridViewGlyphs.CurrentCell = cell;
                            break;
                        }
            }
        }
        #endregion

        #region updatePreview
        private void updatePreview()
        {
            if (_Font != null)
            {
                Graphics gx = panelpreview.CreateGraphics();

                gfx.Clear(_Font.Background);
                gfx.DrawImage(img, imageLocation);
                drawingLines();
                gx.DrawImage(offscreenbmp, 0, 0);

                if (!runStandAlone)
                    refreshRequest();
                propertyGrid1.Refresh();
            }
        }

        private void reInitLinesAndImgLocation()
        {
            /*****occur only when resized*****/
            LinesXYInit();
            imageLocation = new PointF((_baseY.Location.X - _Char._AnchorPoint.X), (_baseX.Location.Y - _Char._AnchorPoint.Y));
            LinesInit();
            /**********/
        }
        #endregion

        #region mouse listeners: Editor_MouseWheel \ panelpreview_MouseDown \ panelpreview_MouseMove \ panelpreview_MouseUp \ panelpreview_MouseMoveAnchoring \ panelpreview_MouseUpAnchoring
        void Editor_MouseWheel(object sender, MouseEventArgs e)
        {
            try
            {
                //checking delta(mouse wheel up or down);
                //based on that either we incr or decr 10% image scale;
                if (e.Delta > 0)
                {
                    imageScale = imageScaleIncrFactor;
                }
                if (e.Delta < 0)
                {
                    imageScale = imageScaleDescrFactor;
                }
                labelZoomInfo.Text = "";
                gfx.TranslateTransform((panelpreview.Width + img.Width) / 2, (panelpreview.Height - img.Height) / 2);
                gfx.ScaleTransform(imageScale, imageScale);
                gfx.TranslateTransform(-(panelpreview.Width + img.Width) / 2, -(panelpreview.Height - img.Height) / 2);

                updatePreview();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        #region panelpreview mouse down,move,up
        private void panelpreview_MouseDown(object sender, MouseEventArgs e)
        {
            panelpreview.Focus();

            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                selectWidthLine(e.X);

                if (isMouseNearChar(e.Location))
                {
                    if (!moveWidthLine)
                        selectAnchorLine(e.X, e.Y);
                    propertyGrid1.SelectedObject = _Char;
                }
                else
                {
                    propertyGrid1.SelectedObject = _Font;
                    DoExpandORCollapse();
                }

                panelpreview.MouseUp += new MouseEventHandler(panelpreview_MouseUp);
                panelpreview.MouseMove += new MouseEventHandler(panelpreview_MouseMove);
            }
        }

        #region mouse move & up for move character
        private void panelpreview_MouseMove(object sender, MouseEventArgs e)
        {
            if (moveWidthLine)
            {
                //_Width.initX(e.X); //update width line;
                _Char.Width = e.X - imageLocation.X; //update char width property;
                boundingBox.Width = _Char.Width; //update bounding box of character
            }

            if (moveAnchorLine)
            {
                _Char.AnchorPointX = _baseY.Location.X - e.X;
                _Char.AnchorPointY = _baseX.Location.Y - e.Y;
                updateImageLocation();
                _Width.init(imageLocation.X + _Char._Width, 10, imageLocation.X + _Char._Width, panelpreview.Height - 10);
            }

            propertyGrid1.Refresh();
            updatePreview();
            panelpreview.Focus();
        }

        private void updateImageLocation()
        {
            imageLocation = new PointF((_baseY.Location.X - _Char._AnchorPoint.X), (_baseX.Location.Y - _Char._AnchorPoint.Y));
            //updating bounding box
            boundingBox.X = imageLocation.X;
            boundingBox.Y = imageLocation.Y;
        }

        private void panelpreview_MouseUp(object sender, MouseEventArgs e)
        {
            panelpreview.MouseMove -= new MouseEventHandler(panelpreview_MouseMove);
            panelpreview.MouseUp -= new MouseEventHandler(panelpreview_MouseUp);
            moveWidthLine = false;
            moveAnchorLine = false;
            panelpreview.Focus();
        }
        #endregion

        #region mouse move & up for setAnchor
        private void panelpreview_MouseMoveAnchoring(object sender, MouseEventArgs e)
        {
            //PointF anchor = new PointF(e.Location.X - imageLocation.X, e.Location.Y - imageLocation.Y);
            //imageLocation = new PointF((_baseY.Location.X - _Char._AnchorPoint.X), (_baseX.Location.Y - _Char._AnchorPoint.Y));
            _Char.AnchorPointX = _baseY.Location.X - e.Location.X;
            _Char.AnchorPointY = _baseX.Location.Y - e.Location.Y;
            updatePreview();
            propertyGrid1.Refresh();
        }

        private void panelpreview_MouseUpAnchoring(object sender, MouseEventArgs e)
        {
            panelpreview.MouseMove -= new MouseEventHandler(panelpreview_MouseMoveAnchoring);
            panelpreview.MouseUp -= new MouseEventHandler(panelpreview_MouseUpAnchoring);
            panelpreview.Focus();
        }
        #endregion
        #endregion

        #endregion

        #region testFont \ testCharacter
        /*
         * Dummy testFont and testCharacter();
         * Both purposes is to make testing faster and prevent
         * going back and forward between this and FontTool to run Editor;
         * Create objects using predifined and the most important properties
         * which is some way are effecting Editor;
         */
        public nFont testFont()
        {
            nFont nfont = new nFont();
            nfont._Name = "testish";
            nfont._Space = 10;
            nfont._Kerning = 2;
            nfont._Leading = 0;
            nfont._xHeight = 18;
            nfont._capHeight = 29;
            nfont._ascenderHeight = 29;
            nfont._descenderHeight = 8;

            //Above Base
            nfont.LineXHeight = true;
            nfont.LineCapHeight = true;
            nfont.LineAscenderHeight = true;
            //Base
            nfont.LineBase = true;
            //Bellow Base
            nfont.LineLeading = true;
            nfont.LineDescenderHeight = true;

            return nfont;
        }

        public nCharacter testCharacter()
        {
            nCharacter nchar = new nCharacter();
            nchar._ImageUri = @"C:\Users\Min0\Desktop\testFont\0x0040.png";
            nchar._Name = "0x0040";
            nchar.guessValues();

            return nchar;
        }
        #endregion

        #region LinesInit \ LinesXYInit \ drawingLines \ drawLine \ initDefaultLines
        private void LinesInit()
        {
            try
            {
                //Initialize lines from Font data;
                _Leading.init(_baseX.Location.X, _baseX.Location.Y + _Font._Leading + _Font._descenderHeight, _baseX.Width, _baseX.Height + _Font._Leading + _Font._descenderHeight);
                _xHeight.init(_baseX.Location.X, _baseX.Location.Y - _Font._xHeight, _baseX.Width, _baseX.Height - _Font._xHeight);
                _capHeight.init(_baseX.Location.X, _baseX.Location.Y - _Font._capHeight, _baseX.Width, _baseX.Height - _Font._capHeight);
                _ascenderHeight.init(_baseX.Location.X, _baseX.Location.Y - _Font._ascenderHeight, _baseX.Width, _baseX.Height - _Font._ascenderHeight);
                _descenderHeight.init(_baseX.Location.X, _baseX.Location.Y + _Font._descenderHeight, _baseX.Width, _baseX.Height + _Font._descenderHeight);
                _Width.init(imageLocation.X + _Char._Width, 10, imageLocation.X + _Char._Width, panelpreview.Height - 10);

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        private void LinesXYInit()
        {
            if (previewDefault)
            {
                _baseX.init(5, panelpreview.Height / 2, panelpreview.Width - 5, panelpreview.Height / 2);
                _baseY.init(panelpreview.Width / 2, 0, panelpreview.Width / 2, panelpreview.Height - 5);
            }
            else
            {
                _baseX.Location = new Point(5, 0);
                _baseX.Size = new Size(panelpreview.Width - 5, panelpreview.Height - 5);
            }
        }

        private void drawingLines()
        {
            if (_Font.LineBase)
            {
                drawLine(_baseX);
                drawLine(_baseY);
                drawLine(_Width);
            }
            if (_Font.LineLeading)
            {
                drawLine(_Leading);
            }
            if (_Font.LineXHeight)
            {
                drawLine(_xHeight);
            }
            if (_Font.LineCapHeight)
            {
                drawLine(_capHeight);
            }
            if (_Font.LineAscenderHeight)
            {
                drawLine(_ascenderHeight);
            }
            if (_Font.LineDescenderHeight)
            {
                drawLine(_descenderHeight);
            }
        }

        private void drawLine(nLine line)
        {
            nPen.Color = line.BackColor;
            nBrush = new SolidBrush(line.BackColor);
            /*
             * Fallowing code handles the problem with text beeing on the same side;
             * with this around 50-50 text are on both sides;
             */
            int positionX = (int)line.Location.X;
            int positionY = (int)(line.Location.Y - 10);
            if (line.Name == "Leading" || line.Name == "xHeight" || line.Name == "BaseX")
                positionX = (int)line.Width - (int)gfx.MeasureString(line.Name, ffont).Width;
            /*
             * checking just for baseY line;
             * since I want text to be draw above line I am using y-10, 
             * BUT that makes baseY text to disapear from the screen;
             */
            if (line.Name == "BaseY" || line.Name == "Width")
                positionY += 10;
            else
                positionY = (int)(line.Location.Y - 10);

            gfx.DrawLine(nPen, line.Location.X, line.Location.Y, line.Width, line.Height);
            gfx.DrawString(line.Name, ffont, nBrush, positionX, positionY);
        }

        private void initDefaultLines()
        {

            _baseX = new nLine();
            _baseX.Name = "BaseX";
            _baseY = new nLine();
            _baseY.Name = "BaseY";

            _Leading = new nLine();
            _Leading.Name = "Leading";
            _xHeight = new nLine();
            _xHeight.Name = "xHeight";
            _capHeight = new nLine();
            _capHeight.Name = "capHeight";
            _ascenderHeight = new nLine();
            _ascenderHeight.Name = "ascenderHeight";
            _descenderHeight = new nLine();
            _descenderHeight.Name = "descenderHeight";
            _Width = new nLine();
            _Width.Name = "Width";


            _baseY.BackColor = Color.Red;
            _Width.BackColor = Color.Red;
            _baseX.BackColor = Color.Red;
        }
        #endregion

        #region buttonORIGIN_Click \ buttonLinesVisible_Click
        private void buttonORIGIN_Click(object sender, EventArgs e)
        {
            offscreenbmp = new Bitmap(panelpreview.Width, panelpreview.Height);
            gfx = Graphics.FromImage(offscreenbmp);
            gfx.ResetTransform();
            previewDefault = true;
            reInitLinesAndImgLocation();
            updatePreview();
        }

        private void buttonLinesVisible_Click(object sender, EventArgs e)
        {
            drawLines = !drawLines;
            _Font.drawAllLines(drawLines);
            updatePreviewTick();
            propertyGrid1.Refresh();
        }
        #endregion

        #region propertyGrid1_PropertyValueChanged
        private void propertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
        {
            updatePreview();
        }
        #endregion

        #region isMouseNearChar \ initBoundingBox \ updatePreviewTick
        private bool isMouseNearChar(PointF location)
        {
            bool isMouseNear = false;

            if (boundingBox.Contains(location))
                isMouseNear = true;

            return isMouseNear;
        }

        private void initBoundingBox()
        {
            boundingBox.X = _baseY.Location.X;
            boundingBox.Y = _baseX.Location.Y - _Font.ascenderHeight;
            boundingBox.Width = _Char.Width;
            boundingBox.Height = _Font.ascenderHeight + _Font._descenderHeight;
        }

        private void updatePreviewTick()
        {
            timerUpdatePreview.Start();
        }
        #endregion

        #region dataGridViewInit \ dataGridViewLoad \ dataGridViewGlyphs_MouseDown \ dataGridViewGlyphs_KeyDown
        private void dataGridViewInit()
        {
            dataGridViewGlyphs.Rows.Clear();
            dataGridViewGlyphs.Columns.Clear();
            imgWidth = dataGridViewGlyphs.Height - SystemInformation.HorizontalScrollBarHeight;

            int columnsPerWidth = _Font.Characters.Count;
            int columnWidth = imgWidth;

            // Dynamically create the columns
            for (int index = 0; index < columnsPerWidth; index++)
            {
                DataGridViewImageColumn dataGridViewColumn = new DataGridViewImageColumn();
                dataGridViewGlyphs.Columns.Add(dataGridViewColumn);
                dataGridViewGlyphs.Columns[index].Width = columnWidth;
            }

            dataGridViewGlyphs.Rows.Add();
            dataGridViewGlyphs.Rows[0].Height = columnWidth;
        }

        private void dataGridViewLoad()
        {
            int columnIndex = 0;
            int rowIndex = 0;
            for (int index = 0; index < _Font._Characters.Count; index++)
            {
                Image image = Helper.ResizeImage(_Font._Characters[index]._ImageUri, imgWidth, imgWidth, false);

                dataGridViewGlyphs.Rows[rowIndex].Cells[columnIndex].Value = image;
                dataGridViewGlyphs.Rows[rowIndex].Cells[columnIndex].ToolTipText = _Font._Characters[index]._Name;
                columnIndex++;
            }

            foreach (DataGridViewRow row in dataGridViewGlyphs.Rows)
                foreach (DataGridViewCell cell in row.Cells)
                    if (cell.Value == null)
                    {
                        DataGridViewCellStyle dataGridViewCellStyle = new DataGridViewCellStyle();
                        dataGridViewCellStyle.NullValue = null;
                        dataGridViewCellStyle.Tag = "BLANK";
                        cell.Style = dataGridViewCellStyle;
                    }
        }

        private void dataGridViewGlyphs_MouseDown(object sender, MouseEventArgs e)
        {
            _Char = _Font.getCharacter(dataGridViewGlyphs.CurrentCell.ToolTipText);
            updatePreviewTick();
            reInitLinesAndImgLocation();
            propertyGrid1.SelectedObject = _Char;
            propertyGrid1.Refresh();
        }

        private void dataGridViewGlyphs_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Escape)
            {
                closeCode();
            }
            //if(e.KeyData == Keys.Left)
            //    Console.WriteLine("LEFT");
            if (e.KeyData == Keys.Right || e.KeyData == Keys.Left)
            {
                _Char = _Font.getCharacter(dataGridViewGlyphs.CurrentCell.ToolTipText);
                updatePreviewTick();
                reInitLinesAndImgLocation();
                propertyGrid1.SelectedObject = _Char;
                propertyGrid1.Refresh();
            }
        }
        #endregion

        #region Editor_KeyDown \ Editor_ResizeEnd\ closeCode \ splitContainer1_SplitterMoved \ initToolTips
        private void Editor_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Escape)
            {
                closeCode();
            }
        }

        void closeCode()
        {
            this.Dispose();
        }

        private void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
        {
            reInitLinesAndImgLocation();
            updatePreviewTick();

            if (!runStandAlone)
            {
                dataGridViewInit();
                dataGridViewLoad();
            }
        }

        private void Editor_ResizeEnd(object sender, EventArgs e)
        {
            if (this.WindowState != FormWindowState.Minimized)
            {
                offscreenbmp = new Bitmap(panelpreview.Width, panelpreview.Height);
                gfx = Graphics.FromImage(offscreenbmp);
                if (!runStandAlone)
                {
                    dataGridViewInit();
                    dataGridViewLoad();
                }
                reInitLinesAndImgLocation();
                updatePreviewTick();
            }
        }

        private void initToolTips()
        {
            ToolTip TT = new ToolTip();
            TT.IsBalloon = true;
            TT.SetToolTip(buttonORIGIN, "set preview to default");
            TT.SetToolTip(buttonLinesVisible, @"Show\Hide lines");
            TT.SetToolTip(panelpreview, "Keys UP,DOWN,LEFT,RIGHT moves Anchor point. \nClick character to drag. \nClick elsewhere to change shown properties.");
        }
        #endregion

        void panelpreview_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Escape)
            {
                closeCode();
                return;
            }
            if (e.KeyData == Keys.Left)
            {
                _Char.AnchorPointX = (float)Math.Round((_Char.AnchorPointX - moveAnchorFactor), 2);
            }
            if (e.KeyData == Keys.Right)
            {
                _Char.AnchorPointX = (float)Math.Round((_Char.AnchorPointX + moveAnchorFactor), 2);
            }
            if (e.KeyData == Keys.Up)
            {
                _Char.AnchorPointY = (float)Math.Round((_Char.AnchorPointY + moveAnchorFactor), 2);
            }
            if (e.KeyData == Keys.Down)
            {
                _Char.AnchorPointY = (float)Math.Round((_Char.AnchorPointY - moveAnchorFactor), 2);
            }
            if (e.KeyData == Keys.Z)
            {
                Undo();
            }
            if (e.KeyData == Keys.Y)
            {
                Redo();
            }

            updateImageLocation();
            reInitLinesAndImgLocation();
            updatePreviewTick();
            propertyGrid1.Refresh();
        }

        private void buttonUndo_Click(object sender, EventArgs e)
        {
            Undo();
        }

        private void Undo()
        {

            _Char.gcmdManager.Undo(_Char);

            updateImageLocation();
            reInitLinesAndImgLocation();
            updatePreviewTick();
        }

        private void buttonRedo_Click(object sender, EventArgs e)
        {
            Redo();
        }

        private void Redo()
        {
            _Char.gcmdManager.Redo(_Char);

            updateImageLocation();
            reInitLinesAndImgLocation();
            updatePreviewTick();
        }

        void zoomContextMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            switch (e.ClickedItem.Text)
            {
                case "default":
                    buttonORIGIN_Click(this, null);
                    break;
                case "25%":
                    updateZoom(0.25f);
                    break;
                case "50%":
                    updateZoom(.5f);
                    break;
                case "75%":
                    updateZoom(.75f);
                    break;
                case "100%":
                    updateZoom(1f);
                    break;
                case "125%":
                    updateZoom(1.25f);
                    break;
                case "150%":
                    updateZoom(1.5f);
                    break;
                case "175%":
                    updateZoom(1.75f);
                    break;
                case "200%":
                    updateZoom(2f);
                    break;
                default:
                    break;
            }
        }

        private void updateZoom(float zoom)
        {
            zoomContextMenu.Visible = false;
            imageScale = zoom;
            labelZoomInfo.Text = zoom * 100 + "%";
            gfx.ResetTransform();
            gfx.TranslateTransform((panelpreview.Width + img.Width) / 2, (panelpreview.Height - img.Height) / 2);
            gfx.ScaleTransform(imageScale, imageScale);
            gfx.TranslateTransform(-(panelpreview.Width + img.Width) / 2, -(panelpreview.Height - img.Height) / 2);

            timerUpdatePreview.Start();
        }

        public void DoExpandORCollapse()
        {
            GridItem root = this.propertyGrid1.SelectedGridItem;
            while (root.Parent != null)
            {
                root = root.Parent;
            }
            root.GridItems[0].Expanded = true; //first category
            root.GridItems[1].Expanded = false;
            root.GridItems[2].Expanded = false;
        }

        private void selectWidthLine(int mouseX)
        {
            if (mouseX + 1 >= _Width.Location.X && mouseX - 1 <= _Width.Width)
                moveWidthLine = true;
        }

        private void selectAnchorLine(int mouseX, int mouseY)
        {
            moveAnchorLine = true;
        }

        private void buttonSettings_Click(object sender, EventArgs e)
        {
            using (commandBacklog cb = new commandBacklog(_Char.gcmdManager))
            {
                cb.execute = new commandBacklog.executeCommand(executeCommand);
                if (cb.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    cb.Close();
            }
            //using (editorSettings es = new editorSettings(imageScaleIncrFactor, imageScaleDescrFactor, moveAnchorFactor))
            //{
            //    es.receiveUpdate = new editorSettings.receiveSettingsUpdate(updateFactors);
            //    if (es.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            //        es.Close();
            //}
        }

        private void executeCommand(commandGlyph cmd)
        {
            _Char.gcmdManager.executeCommand(_Char, cmd);

            updateImageLocation();
            reInitLinesAndImgLocation();
            updatePreviewTick();

        }

        private void updateFactors(float scaleIncr, float scaleDecr, float moveAnch)
        {
            Console.WriteLine(string.Format("[{0}][{1}][{2}]", imageScaleIncrFactor, imageScaleDescrFactor, moveAnchorFactor));
            if (scaleIncr != imageScaleIncrFactor)
                imageScaleIncrFactor = scaleIncr;
            if (scaleDecr != imageScaleDescrFactor)
                imageScaleDescrFactor = scaleDecr;
            if (moveAnch != moveAnchorFactor)
                moveAnchorFactor = moveAnch;
            Console.WriteLine(string.Format("[{0}][{1}][{2}]", imageScaleIncrFactor, imageScaleDescrFactor, moveAnchorFactor));
        }
    }
}
